<?php

if (!isset($_GET['id'])) $id = 0;
else $id = $_GET['id'];

if ($id>0) {
	$query = "SELECT * FROM kemikalija WHERE id=" . $id . ";";
	$result = myQuery($query);
	if (! ($row = mysql_fetch_array($result))) myDie("Kriticna greska sa id od kemikalija... ", "kemikalije.php");
	$action = "edit&type=kemikalija&id=" . $row['id'];
}
else $action = "new&type=kemikalija";

print("<form method='POST' action=\"exec/kemikalije.php?action=" . $action . "\">");
?>

<table>
<tr>
<td width='50%'>
	<div class='content'>
	<span class='contentTitle'> Opće informacije</span>
	<table class='tableResult' cellspacing='0' width='100%'>
	<tr> <th scope='row' class='spec' width='110px' > Naziv </th> 
		<td> <input type='text' name='kemNaziv' id='kemNaziv' size='38'
				<?php if ($id>0) print("value='" . $row['naziv'] . "'");?> > </td> </tr>

	<tr> <th scope='row' class='spec' > Molekularna<br>formula </th> 
		<td> <input type='text' name='kemFormula' id='kemFormula' size='38'
				<?php if ($id>0) print("value='" . $row['formula'] . "'");?> > </td> </tr>
				
	<tr> <th scope='row' class='spec' > Molekularna<br>masa </th> 
		<td> <input type='text' name='kemMasa' id='kemMasa' size='32'
				<?php if ($id>0) print("value='" . $row['masa'] . "'");?> > g/mol </td> </tr>
						
	<tr> <th scope='row' class='spec' > Sinonimi </th> 
		<td valign="middle">  
			<input type='text' name='kemSinonimi' id='kemSinonimi' size='32' readonly="readonly"
				<?php if ($id>0) print("value='" . $row['naziv'] . "'");?> > 
			<img class='button' src='images/add.png' onclick="fillOptionWithInput('kemSinonimi')">
			<img class='button' src='images/delete.png' onclick="removeOption('kemSinonimi')">
		
		</td> </tr>
	
	</table>
	</div>
</td>

<td rowspan='3' valign="top">
	<div class='content'>
	<span class='contentTitle'> Sigurnosne informacije </span>
	<table class='tableResult' cellspacing='0' width='100%'>
	<tr> 
		<th scope='row' class='spec' > Info </th> 
		<td> 
			<textarea name='kemInfo' id='kemInfo' rows='4' cols='39'><?php if ($id>0) print($row['info']); ?></textarea>
		</td>
	</tr>
	
	<tr> 
		<th scope='row' class='spec' > Info o <br>spremanju </th> 
		<td> 
			<textarea name='kemPohrana' id='kemPohrana' rows='4' cols='39'><?php if ($id>0) print($row['pohrana']); ?></textarea>
		</td>
	</tr>
	
	<tr>
		<th scope='row' class='spec' width='90px'> Hazard<br>kodovi </th> 
		<td>
			<select name='kemSelHazard' id='kemSelHazard' onchange="fillOption(this,'kemHazard')">
				<?php printOptionsOfAtributes("hazard", "naziv")?>
			</select>
			<img class='button' src='images/delete.png' onclick="removeOption('kemHazard')"><br>
			<input type='text' name='kemHazard' id='kemHazard' size='40' readonly="readonly"> 
		</td> 
	</tr>
			
	<tr> 
		<th scope='row' class='spec'> Zaštitna oprema </th> 
		<td> 
			<textarea name='kemOprema' id='kemOprema' rows='4' cols='39'><?php if ($id>0) print($row['oprema']); ?></textarea>
		</td> 
	</tr>
			
	<tr> 
		<th scope='row' class='spec'> Rizik </th> 
		<td> 
			<textarea name='kemRizik' id='kemRizik' rows='4' cols='39'><?php if ($id>0) print($row['rizik']); ?></textarea>
		</td>
	</tr>
			
	<tr> 
		<th scope='row' class='spec'> Sigurnost </th> 
		<td> 
			<textarea name='kemSigurnost' id='kemSigurnost' rows='4' cols='39'><?php if ($id>0) print($row['sigurnost']); ?></textarea>
		</td>
	</tr>
			
	<tr> 
		<th scope='row' class='spec'> Prva<br>pomoć </th> 
		<td> 
			<textarea name='kemPomoc' id='kemPomoc' rows='4' cols='39'><?php if ($id>0) print($row['pomoc']); ?></textarea>
		</td>
	</tr>
	
	<tr>
		<th scope='row' class='spec' colspan='2'><center><input type='submit' value='Spremi promjene'></center>  </th>
	</tr>
	
	</table>
	</div>
</td>
</tr>

<tr>
<td>
	<div class='content'>
	<span class='contentTitle'> Svojstva kemikalije</span>
	<table class='tableResult' cellspacing='0' width='100%'>
			
	<tr> 
		<th scope='row' class='spec' width='110px'> Gustoća </th> 
		<td>
			<input type='text' name='kemGustoca' id='kemGustoca' size="18"
				<?php if ($id>0) print("value='" . $row['gustoca'] . "'");?> > g/cm3 pri 
			
			<input type='text' name='kemGustocaDodatak' id='kemGustocaDodatak' size='5'
				<?php if ($id>0) print("value='" . $row['gustoca_dodatak'] . "'");?> > °C
		</td> 
	</tr>
				
	<tr> 
		<th scope='row' class='spec' > Zapaljenje </th> 
		<td> 
			<input type='text' name='kemSamozapaljenje' id='kemSamozapaljenje' size='35'
				<?php if ($id>0) print("value='" . $row['samozapaljenje'] . "'");?> > °C 
		</td> 
	</tr>
				
	<tr> 
		<th scope='row' class='spec' > Ključanje </th> 
		<td> 
			<input type='text' name='kemKljucanje' id='kemKljucanje' size='35'
				<?php if ($id>0) print("value='" . $row['kljucanje'] . "'");?> > °C 
		</td>
	</tr>
				
	<tr> 
		<th scope='row' class='spec' > Otapanje </th> 
		<td> 
			<input type='text' name='kemOtapanje' id='kemOtapanje' size='35'
				<?php if ($id>0) print("value='" . $row['otapanje'] . "'");?> > °C
		</td>
	</tr>
				
	<tr> 
		<th scope='row' class='spec' > Kemijska čistoća </th> 
		<td> 
			<input type='text' name='kemCistoca' id='kemCistoca' size='38'
				<?php if ($id>0) print("value='" . $row['cistoca'] . "'");?> > 
		</td> 
	</tr>
				
	<tr> 
		<th scope='row' class='spec' > Otapala </th> 
		<td> 
			<select name='kemSelOtapala' id='kemSelOtapala' onchange="fillOption(this,'kemOtapala')">
				<?php printOptionsOfAtributes("otapalo", "naziv")?>
			</select>
			<img class='button' src='images/delete.png' onclick="removeOption('kemOtapala')"><br>
			<input type='text' name='kemOtapala' id='kemOtapala' size='38' readonly="readonly"
				<?php if ($id>0) print("test");?> > 
		</td> 
	</tr>
	</table>
	</div>
</td>
</tr>

<tr>
<td>
	<div class='content'>
	<span class='contentTitle'> Pohrana i narudžba </span>
	<table class='tableResult' cellspacing='0' width='100%'>
	<tr> 
		<th scope='row' class='spec' > Cat number </th> 
		<td> 
			<input type='text' name='kemCat' id='kemCat' size='38'
			<?php if ($id>0) print("value='" . $row['cat'] . "'");?> > 
		</td> 
	</tr>
			
	<tr> 
		<th scope='row' class='spec' > Proizvođači </th> 
		<td> 
			<select name='kemSelProizvodjaci' id='kemSelProizvodjaci' onchange="fillOption(this,'kemProizvodjaci')">
				<?php printOptionsOfAtributes("proizvodjac", "naziv")?>
			</select>
			<img class='button' src='images/delete.png' onclick="removeOption('kemProizvodjaci')" ><br>
			<input type='text' name='kemProizvodjaci' id='kemProizvodjaci'  size='38' readonly="readonly"
			<?php if ($id>0) print("test");?> > 
		</td> 
	</tr>
			
	<tr> 
		<th scope='row' class='spec' > Spremanje<br>na odjelu </th> 
		<td> 
			<select name='kemSelOdjeli' id='kemSelOdjeli' onchange="fillOption(this,'kemOdjeli')">
				<?php printOptionsOfAtributes("odjel", "naziv")?>
				<option onclick="">
			</select>
			<img class='button' src='images/delete.png' onclick="removeOption('kemOdjeli')"><br>
			<input type='text' name='kemOdjeli' id='kemOdjeli' size='38' readonly="readonly"
			<?php if ($id>0) print("test");?> > 
		</td> 
	</tr>
	</table>
	</div>
</td>
</tr>
</table>

<?php print("</form>"); ?>